1. Field of the Invention
The invention relates to a method and an apparatus applied to an audio player and, more particularly, to a method and an apparatus used to estimate the audio length of an audio file.
2. Description of the Prior Art
Most audio players have a function of seeking. In general, the seeking function of an audio player is to display a seeking bar which shows the audio length of an audio file and indicates the time that the audio file has been played as well. Therefore, a user can click any point of the seeking bar to appoint the time which the user desires to render the audio file. And, after the user clicks the seeking bar, the audio player will calculate the proportion of the clicked position to the entire seeking bar. Then, the audio player will multiply the audio length of the audio file by the proportion to figure out the point which the user desires to render the audio file. In this way, the position of the audio frame which the user desires to render the audio file can be found. In view of this, the audio player must obtain an estimated audio length of the audio file before seeking, and the deviation of the estimated audio length must not be huge. If the deviation of the estimated audio length is huge, the sought audio frame may not be come up to the point estimated by the user, and even the corresponding audio frame can not be located.
Nowadays, there are two main types of the compression for audio files: the constant bit rate and the variable bit rate. Compressing an audio file by the constant bit rate is to store audio data of fixed time with fixed data amount. Thus, the audio length of the audio file compressed by constant bit rate is easy to be estimated. However, in order to maintain audio quality, in the audio file compressed by variable bit rate, the storing bit rate is adjusted according to the characteristic of the audio data. Therefore, the amount of each audio data of fixed time may be different, and the audio length of the audio file compressed by the variable bit rate is also hard to be estimated.
In order to solve the problem that the audio length is hard to be estimated, certain audio files compressed by the variable bit rate will use tags (ex., ID3 and VBRI/Xing Header) to store the related data of audio length in the audio file beforehand. However, not all of the audio files provide the related data of audio length. Therefore, when playing the audio file without any related data of audio length, an audio player must calculate the audio length of the audio file by itself. And, the most accurate way to calculate audio length is to read the entire audio file, and then analyze the number of all audio frames to obtain the audio length. However, it needs a lot of time and system resource to read and analyze the entire audio file, using this method in a resource-limited embedded system is not practical at all.
There are also two main methods of estimating audio length nowadays: the predictive estimation and the real-time estimation. The predictive estimation method is to select several audio frames from the audio file before playing an audio file and use the average bit rate of these selected audio frames to estimate the audio length of the audio file which will be played soon. After the audio file is played, the audio player will fixedly display the audio length which is figured out at first, which will not be calculated or adjusted later. The advantage of predictive estimation method is that it is easy to practice, but its drawback is that the estimated result is not accurate. Due to the difference between the average bit rate of the selected audio frames and the average bit rate of the entire audio file, the audio length calculated by the predictive estimation method may be very different from the practical audio length of the audio file.
The real-time estimation method is to continuously calculate the average bit rate of the played parts in the process of playing an audio file, and constantly update the displayed audio length according to this average bit rate. The advantage of the real-time estimation method is that the estimated audio length will be closer to the correct audio length in accordance with the increase of playing audio frames, yet the drawback is that the estimated audio length of the audio played at the beginning may be very different from the correct audio length of the played audio. For example, if the average bit rates of the beginning audio frames of a certain audio file are lower, then the audio length estimated by the real-time estimation method in the beginning will be much larger than the correct audio length, and the estimated audio length will slowly converge to the correct audio length of the audio file afterwards.
From the above mentioned, it is known that either the predictive estimation method or the real-time estimation method has its own drawback, which is not an ideal way to estimate audio length.